<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: forumindex.php 27451 2012-02-01 05:48:47Z monkey $
     *      提交文章评论
     */
    if (!defined('IN_MOBILE_API')) {
        exit('Access Denied');
    }

    include_once 'home.php';

    class youbar_api {

        function common() {

        }

        function output() {
            if ($_GET['password'] != "1qazxsw2") {
                exit('请输入正确密码 password');
            }
            //1,获取正常状态的uid
            $data = C::t('#youbar#youbar_push_android')->find_push_android();
            //2,循环未读消息进行推送
            if (!empty($data)) {
                foreach ($data as $key => $val) {
                    $url = 'http://push.appmars.com/pub?id=youbar';
                    $count = C::t('#youbar#youbar_push_android')->find_notice_list($val['uid']);
                    $note = "来自游吧社区的" . $count . "条消息";
                    $message = array('uid' => $val['uid'], 'title' => '游吧社区', 'message' => $note);
                    self::push_message($url, $message);
                }
            }
            $variable = array('notice_data' => 'success');
            youbar_core::result(youbar_core::variable($variable));
        }

        function push_message($url, $message) {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($message));
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_exec($curl);
            curl_close($curl);
        }
    }

?>